#ifndef SL_CULL_NODE_VISITOR_H_
#define SL_CULL_NODE_VISITOR_H_
#include "NodeVisitor.h"
#include "StateGraph.h"
#include "Camera.h"
#include "Frustum.h"
namespace sl
{
	// Create the new state to render 
	class Node;
	class GeoNode;
	class GroupNode;
	class BoundingBox;
	class CullNodeVisitor : public sl::NodeVisitor
	{
	public:
		CullNodeVisitor(void);
		~CullNodeVisitor(void);

		virtual void Apply( sl::Node * pNode );
		virtual void Apply( sl::GeoNode * pGeoNode );
		virtual void Apply( sl::GroupNode * pGroupNode );


		// using to store the state
		void SetStateGraph( sl::StateGraph * pStateGraph ){ m_rStateGraph = pStateGraph; };
		sl::StateGraph * GetStateGraph(){ return m_rStateGraph.get(); };

		// set the camera
		void SetCurrentCamera( sl::Camera * pCamera );
		sl::Camera * GetCurrentCamera(){ return m_rCamera.get(); }

		bool IsCulled( sl::Node * pNode );

		bool IsCulled( sl::BoundingBox * pBound );
		
		void PushAtrributeSet( sl::DrawAttributeSet * pAttributeSet );

		void PopAtrributeSet( sl::DrawAttributeSet * pAtrributeSet );

		void AddDrawableAndDepth( sl::Drawable * drawable,sl::Matrix4 & view, float depth );

		void MakeFrustum( sl::Camera * pCamera );

	private:
		float makeDistanse( Vector3 & left, Matrix4 & right );
		ref_ptr<sl::StateGraph>		m_rStateGraph;
		ref_ptr<sl::Camera>			m_rCamera;
		ref_ptr<sl::Frustum>		m_rFrustum;

	};
}

#endif

